
import Vue from 'vue'
import {axios} from '@/utils/request'
import {downFilePostJSON ,downFilePostUrl} from "@/api/fileDownload";
import fileDownload from "js-file-download";

export function getListAxios(data) {
    return axios({
        url: "/vatoutinv/matchFlow/pageApply",
        method: 'post',
        data
    })
}



/**
 * 导出
 * @param data
 * @returns {AxiosPromise}
 */
export function exportList(parameter,method) {
    return downFilePostJSON('/vatoutinv/matchFlow/export', parameter,method).then((data) => {
        if (!data || data.data.size === 0) {
            Vue.prototype['$message'].warning('文件下载失败')
            return
        }

        var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
        var contentDisposition = decodeURI(data.headers['content-disposition'])
        var result = patt.exec(contentDisposition)


        try {
            var fileName = result[1]
            fileName = fileName.replace(/\"/g, '')
        } catch (error) {
            return Vue.prototype['$message'].warning('文件下载失败')
        }
        if(!fileName) return Vue.prototype['$message'].warning('文件下载失败')

        fileDownload(data.data,fileName)
    })
}

export function fastAdd(params) {
    return axios({
        url: '/vatoutinv/matchFlow/fastAdd',
        method: 'post',
        params
    })
}

// 子页面的查询
export function pageInvoiceSon(data) {
    return axios({
        url: '/vatoutinv/matchFlow/pageInvoice',
        method: 'post',
        data
    })
}

// 匹配流水
export function queryFlowByAutoOrHand(data) {
    return axios({
        url: '/vatoutinv/matchFlow/queryFlowByAutoOrHand',
        method: 'post',
        data
    })
}

// 匹配流水 - 保存 和箭头(左右)
export function itemMatchFlow(data) {
    return axios({
        url: '/vatoutinv/matchFlow/itemMatchFlow',
        method: 'post',
        data
    })
}

// 匹配流水 - 右侧获取列表  + 外层列表的详情,再次根据明细查询 流水
export function queryFlowByItem(data) {
    return axios({
        url: '/vatoutinv/matchFlow/queryFlowByItem',
        method: 'post',
        data
    })
}
export function saveAllowError(data) {
    return axios({
        url: '/vatoutinv/matchFlow/saveAllowError',
        method: 'post',
        data
    })
}
// 匹配流水 - 审批或者申请的时候,获取详情 
export function getApplyDetail(id) {
    return axios({
        url: '/vatoutinv/matchFlow/getApplyDetail?applyId='+id,
        method: 'post',
    })
}
// 匹配流水 - 审批或者申请的时候,获取详情 
export function getMatchDetail(id) {
    return axios({
        url: '/vatoutinv/matchFlow/getMatchDetail?matid='+id,
        method: 'post',
    })
}


// 匹配流水 - 导入 
export function readExcel(parameter,method) {
    return downFilePostUrl('/vatoutinv/matchFlow/readExcel', parameter,method)
}
